//
// Created by wujehy on 2020/8/3.
//

#ifndef AUTH_RAFT_BUSINESSMANAGER_H
#define AUTH_RAFT_BUSINESSMANAGER_H

#include <map>
#include "baseType.h"

#include "ListernerManager.h"
#include "ContextManager.h"
#include "DaoManager.h"

/**
 * @brief 业务管理器
 */
class BusinessManager : ManagerBase
{
    friend class BusinessBase<NetWorkWarpper>;

    friend class ListernerManager;

    friend class ContextManager;

private:
    NetWorkWarpper *netWorkWarpper = nullptr;
    ListernerManager m_listernerManager;
    ContextManager contextManager;
    DaoManager daoManager;
    std::map<int, BusinessBase<NetWorkWarpper> *> m_mod_map;

    /**
     * @brief 注册需要的模块
     */
    void registerMod();

public:
    BusinessManager();

    Type type() override;

    void init();

    /**
     * @brief 路由网络请求包 数据 , 这里进行拆包 并 数据分发
     * @param tcpid 链接上来的tcp id
     * @param netWorkPacket 网络请求包
     * @return
     */
    int route(int64_t tcpid, GeeJoan::Protocol::NetWork::NetWorkPackageRequest *netWorkPacket);

    /**
     * @brief 触发监听器
     * @param type 监听器的类型
     */
    void callListerner(int type);

    virtual ~BusinessManager();

    NetWorkWarpper *getNetWorkWarpper() const;

    ContextManager *getContextManager();

    DaoManager *getDaoManager();

    void setNetWorkWarpper(NetWorkWarpper *netWorkWarpper);

//    int call200(int taskid , int mod , int type_sub ,  );


    int call500(int taskid, std::string errmsg);

    int call200(int taskid, std::string &body);

    int call401(int taskid);

    /**
     * @brief 初始化完成触发
     */
    void init_finished() override;
};


#endif //AUTH_RAFT_BUSINESSMANAGER_H
